import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RedisModule } from '@nestjs-modules/ioredis';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MessageModule } from './modules/message/message.module';
import { UserMessageMapping } from './modules/message/entities/user-message-mapping.entity';
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { AuthModule } from './modules/auth/auth.module';
import { UserModule } from './modules/user/user.module';
import { ActivityModule } from './modules/activity/activity.module';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { databaseConfig } from './config/database.config';
import { redisConfig } from './config/redis.config';
import { StartupLoggerService } from './services/startup-logger.service';
import { OperationLoggerService } from './services/operation-logger.service';
import { OperationLogModule } from './modules/operation-log/operation-log.module';
import { OperationLogInterceptor } from './interceptors/operation-log.interceptor';
import { OperationLog } from './modules/operation-log/entities/operation-log.entity';
import { User } from './modules/user/entities/user.entity';
import { Activity } from './modules/activity/entities/activity.entity';
import { ScheduleModule } from '@nestjs/schedule';
import { LogCleanupService } from './services/log-cleanup.service';
import { ActivityReminderService } from './services/activity-reminder.service';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
@Module({
  imports: [
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '..','static'),
      serveRoot: '/static',
      exclude: ['/api*'],
    }),
    ScheduleModule.forRoot(),
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    TypeOrmModule.forRoot({
      ...databaseConfig,
      synchronize: true, // 恢复自动同步
    }),
    TypeOrmModule.forFeature([Activity, OperationLog, User]),
    RedisModule.forRoot(redisConfig),
    AuthModule,
    ActivityModule,
    UserModule,
    OperationLogModule,
    MessageModule,
  ],
  providers: [
    OperationLoggerService,
    StartupLoggerService,
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: OperationLogInterceptor,
    },
    LogCleanupService,
    ActivityReminderService,
  ],
  exports: [OperationLoggerService],
})
export class AppModule {}
